﻿using LServer.Core.Utils;
using LServer.Model.Logic.Entitys;
using LServer.Model.Managers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace LServer.WebAccount.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class InitController : ControllerBase
    {
        [HttpGet]
        public string Get() 
        {
            return "OK";
        }

        [HttpPost]
        public string Post() 
        {
            string json = Request.HttpContext.Request.Form["json"];
            Dictionary<string,object> dic = JsonConvert.DeserializeObject<Dictionary<string,object>>(json);

            string channelId = dic["ChannelId"].ToString();
            string innerVersion = dic["InnerVersion"].ToString();

            ChannelEntity channelEntity = ChannelConfig.Get(channelId, innerVersion);

            Dictionary<string, object> retDic = new Dictionary<string, object>();
            retDic["ServerTime"] = LFDateTimeUtil.GetTimestamp();
            retDic["SourceVersion"] = channelEntity.SourceVersion;
            retDic["SourceUrl"] = channelEntity.SourceUrl;
            retDic["RechargeUrl"] = channelEntity.RechargeUrl;
            retDic["PayServerNo"] = channelEntity.PayServerNo;
            retDic["TDAppId"] = channelEntity.TDAppId;
            retDic["IsOpenTD"] = channelEntity.IsOpenTD;

            return JsonConvert.SerializeObject(retDic);
        }
    }
}
